<template>
  <div>
    测试
  </div>
</template>

<script>
import { getDepartments } from '@/api/departments'
export default {
  created() {
    getDepartments().then(res => {
      console.log(res)
      console.log(this.convertTreeData(res.depts, ''))
    })
  },
  methods: {
    convertTreeData: function(list, pid) {
      const res = []
      list.forEach(item => {
        if (item.pid === pid) {
          const children = this.convertTreeData(list, item.id)
          if (children.length > 0) {
            item.children = children
          }
          res.push(item)
        }
      })
      return res
    }
  }
}
</script>

<style>

</style>
